package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import jakarta.annotation.Resource;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
// @EnableConfigurationProperties(MinioProperties.class) 对单个配置类进行注册
// @ConfigurationPropertiesScan("com.atguigu.lease.common.minio") 扫描整个包中的配置类，进行注册
@EnableConfigurationProperties(MinioProperties.class)
public class MinioConfiguration {

    @Resource
    private MinioProperties minioProperties;


    // 注册一个配置好的MinioClient放到Spring容器中
    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
    }
}
